﻿using System.ComponentModel;

namespace Chapter08
{
    [Description("Listing 8.1")]//统计创建了多少个实例的Person类
    public class InstanceCountingPerson
    {
        public string Name { get; private set; }//自动属性
        public int Age { get; private set; }

        private static int InstanceCounter { get; set; }
        private static readonly object counterLock = new object();//静态属性锁

        public InstanceCountingPerson(string name, int age)
        {
            Name = name;
            Age = age;

            lock (counterLock)
            {
                InstanceCounter++;
            }
        }
    }
}
